/**
 * Description:
 * Class Name:Canvas
 * Date:2022/3/24 15:20
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第9章_泛型._9_3_类型通配符._9_3_2_设定类型通配符的上限;

import java.util.ArrayList;
import java.util.List;

public class Canvas {
    // 同时在画布上绘制多个形状
    public void drawAll(List<? extends Shape> shapes){
        for (var s :
                shapes) {
            s.draw(this);
        }
    }

    public static void main(String[] args) {
        List<Circle> circleList = new ArrayList<>();
        var c = new Canvas();
        c.drawAll(circleList);
    }
    public void addRectangle(List<? extends Shape> shapes, int index){
        // 下面的代码可以正常运行
        System.out.println(shapes.get(index));
        // 下面的代码将引起编译错误
//        shapes.add(0, new Rectangle());
    }
}
